package com.servlet.response; /**
 * @author wzm
 * @create 2023-06-25 10:27
 */

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet("/rs05")
public class ResponseServlet05 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //响应一个图片到浏览器

        //从磁盘读取文件
        FileInputStream fis = new FileInputStream("f://a.png");
        //获取字节输出流
        ServletOutputStream os = response.getOutputStream();
        //将输入流复制到输出流即可完成流的输出
        IOUtils.copy(fis,os);
        fis.close();

    }
}
